Skip to content

Trim trailing dot from trusted IMDS hostnames - #652

Open
bitterpanda63 wants to merge 3 commits into
mainfrom
fix/trusted-hostname-trailing-dot
Open

Trim trailing dot from trusted IMDS hostnames#652
bitterpanda63 wants to merge 3 commits into
mainfrom
fix/trusted-hostname-trailing-dot

Conversation

@bitterpanda63

@bitterpanda63 bitterpanda63 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

DNS resolvers sometimes return fully-qualified domain names with a trailing dot (e.g. metadata.google.internal.). The previous direct equality check in is_trusted_hostname did not match this form, so GCP IMDS requests could be incorrectly flagged as stored SSRF.

  • Normalize hostname with .lower().rstrip('.') before the trusted-host lookup
  • Add test cases for trailing-dot and uppercase variants

This is the same fix already applied in firewall-go (PR #459 / hostname-trailing-dot). Ported to Python, Ruby, .NET, PHP, and Java.

Test plan

  • poetry run pytest aikido_zen/vulnerabilities/ssrf/imds_test.py passes

Summary by Aikido

Security Issues: 0 🔍 Quality Issues: 1 Resolved Issues: 0

🚀 New Features

  • Added normalize_hostname helper module to canonicalize hostnames across project

⚡ Enhancements

  • Expanded normalization to lowercase and decode punycode if present

🐛 Bugfixes

  • Normalized hostnames before trusted-host lookup to handle trailing dots

🔧 Refactors

  • Moved normalize_hostname implementation to helpers to avoid import cycle

More info

bitterpanda63 and others added 3 commits June 8, 2026 17:02
DNS resolvers may return hostnames with a trailing dot (e.g.
`metadata.google.internal.`), which is a valid FQDN form. The previous
direct equality check failed to match these, so they would not be
skipped and could cause false-positive stored-SSRF blocks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Expand normalize_hostname (sinks/socket) to also lowercase and strip
trailing dots so it is a proper canonical form for all hostname
comparisons. Use it in is_trusted_hostname instead of inline .lower()
.rstrip(".").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Importing from sinks.socket in vulnerabilities.ssrf.imds created a
cycle through sinks.socket.__init__ → aikido_zen.vulnerabilities.
Move the implementation to helpers/normalize_hostname.py and have
sinks/socket/normalize_hostname.py re-export from there.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bitterpanda63
bitterpanda63 force-pushed the fix/trusted-hostname-trailing-dot branch from fc46c9a to 6e725f5 Compare July 28, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant